﻿using System;
using System.Text;

namespace System.Text
{
    public static partial class StringHelper
    {
        /// <summary>
        /// 忽略大小写的字符串比较
        /// </summary>
        /// <param name="value"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static bool EqualIgnoreCase(string value, string text)
        {
            return string.Equals(value, text, StringComparison.OrdinalIgnoreCase);
        }

        /// <summary>
        /// 忽略大小写判断是否包含指定字符
        /// </summary>
        /// <param name="source"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool ContainIgnoreCase(string source, string value)
        {
            return System.Globalization.CultureInfo.InvariantCulture.CompareInfo.IndexOf(source ?? string.Empty, value ?? string.Empty, System.Globalization.CompareOptions.IgnoreCase) > -1;
        }

        /// <summary>
        /// 是否空或者空白字符串
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsNullOrWhiteSpace(string value)
        {
            if (value != null)
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (!char.IsWhiteSpace(value[i])) return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 拆分字符串
        /// </summary>
        /// <param name="value"></param>
        /// <param name="separators"></param>
        /// <returns></returns>
        public static string[] Split(string value, params string[] separators)
        {
            if (string.IsNullOrEmpty(value))
                return new string[0];
            return value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
        }

        /// <summary>
        /// 去除所有空格符
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string TrimAll(string value)
        {
            return System.Text.RegularExpressions.Regex.Replace(value ?? string.Empty, @"\s", "");
        }
    }
}
